package mac10.util;

import mac10.models.Point;


public class Node extends Point implements Comparable<Node>{

	/**
     * 
     */
    private static final long serialVersionUID = 2186978901494720174L;

    private int g, f;
	
	private Node predecessor;
	
	public Node(Point p, int g, int f)
	{
		this(p, g, f, null);
	}
	
	public Node(Point p, int g, int f, Node predecessor)
	{
		super(p);
		this.g = g;
		this.f = f;
		this.predecessor = predecessor;
	}
	
	/**
	 * @return the g
	 */
	public int getG() {
		return g;
	}
	
	/**
	 * @return the f
	 */
	public int getF() {
		return f;
	}
	
	public void updateFAndPredecessor(int f, Node predecessor)
	{
		if (this.f > f)
		{
			this.f = f;
			this.predecessor = predecessor;
		}
	}

	/**
	 * @return the predecessor
	 */
	public Node getPredecessor() {
		return predecessor;
	}
	
	public String toString()
	{
		return "(" + x + ", " + y + ")";
	}

	@Override
	public int compareTo(Node n) {
		if (this.f < n.f)
			return -1;
		else if (this.f > n.f)
			return 1;
		else
			return 0;
	}
}
